function Value(age, name) {
    this.age = age;
    this.name = name;
}

function SequenceList() {
    this.data = [];
    this.listSize = 0;

    if (!SequenceList.prototype.appendNode) {
        SequenceList.prototype.appendNode = function (Value) {
            this.data[this.listSize++] = Value;
        }
    }

    if (!SequenceList.prototype.isEmpty) {
        SequenceList.prototype.isEmpty = function () {
            return this.listSize == 0;
        }
    }

    if (!SequenceList.prototype.delList) {
        SequenceList.prototype.delList = function (pos) {

            if (this.isEmpty()) {
                return false;
            }
            if (pos <= 0 || pos > this.listSize) {
                return false;
            }

            for (var i = pos; i < this.data.length; i++) {
                this.data[i - 1] = this.data[i];
            }

            return true;

        }
    }

    if (!SequenceList.prototype.insert) {
        SequenceList.prototype.insert = function (pos, value) {
            if (pos <= 0 || pos > this.listSize + 1) {
                return false;
            }


            for (var i = this.listSize - 1; i >= pos - 1; i--) {
                this.data[i + 1] = this.data[i];
            }
            this.data[pos - 1] = value;
            this.listSize++;
            return true;


        }
    }

    if(!SequenceList.prototype.lens) {
        SequenceList.prototype.lens=function() {
            return this.data.length;
        }
    }

   if(!SequenceList.prototype.showList) {
       SequenceList.prototype.showList=function() {
           for(var i=0;i<this.data.length;i++) {
                console.info(this.data[i].name+":"+this.data[i].age);
           }
       }
   }

    if(!SequenceList.prototype.sortByAge){
        SequenceList.prototype.sortByAge=function() {
            for(var i =0;i<this.data.length;i++) {
                for(var j =0;j<this.data.length-1-i;j++) {
                    if(this.data[j].age>this.data[j+1].age) {
                        var temp =this.data[j];
                        this.data[j]=this.data[j+1];
                        this.data[j+1]=temp;
                    }
                }
            }
        }
    }

    if(!SequenceList.prototype.reverseList) {
        SequenceList.prototype.reverseList= function () {
           var i = 0;
           var j =this.data.length-1;

            while(i<j) {
                var temp = this.data[i];
                this.data[i] = this.data[j];
                this.data[j] = temp;
                i++;
                j--;
            }

        }
    }

}

var list = new SequenceList();
var v1 = new Value(33,"jack");
var v2 =new Value(14,"peter");
var v3 =new Value(55,"lil");
var v4 =new Value(22,"zz");
list.appendNode(v1);
list.appendNode(v2);
list.appendNode(v3);
list.appendNode(v4);
list.sortByAge();
list.showList();

var v5=new Value(100,"v5");
console.info("------------");
list.insert(2,v5);
list.showList();

console.info("---delete----");
list.delList(2);
list.showList();
console.info("---reverseList---");
list.reverseList();
list.showList();

